import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.FutureTask;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;


public class Main {

	public static void main(String[] args) {
		
		Callable<String> callable = new Callable<String>() {

			@Override
			public String call() throws Exception {
				for (int i = 0; i < 10000; i++) {
					System.out.println(i);
					Thread.sleep(20);
				}
				
				
				return null;
			}
		};
		FutureTask<String> task = new FutureTask<String>(callable);
		ExecutorService service = Executors.newFixedThreadPool(20);
		service.execute(task);
		
		try {
			TimeUnit.SECONDS.sleep(5);
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
//		task.cancel(true);
		System.out.println(task.isCancelled());
		try {
			task.get(5,TimeUnit.SECONDS);
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (ExecutionException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (TimeoutException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		

	}

}
